import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { DateTimeUtils } from '../../common/DateTimeUtil';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the BookclassroomPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-bookclassroom',
  templateUrl: 'bookclassroom.html',
})
export class BookclassroomPage {
  classroomno:any;
  startdate: string;
  enddate: string;
  constructor(public navCtrl: NavController, public navParams: NavParams, public busi:BusiProvider,public native:NativeProvider) {
    this.classroomno = this.navParams.get("classroomno");
    let currentDate = DateTimeUtils.getCurrentDate();
    this.startdate = DateTimeUtils.getIonDateTimeAddHours(currentDate,1);
    this.enddate = DateTimeUtils.getIonDateTimeAddHours(currentDate, 2);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad BookclassroomPage');
  }

  book(){
    let params= {
      classroomno:this.classroomno,
      startdate: this.startdate.replace("T"," ").replace(":00Z",""),
      enddate: this.enddate.replace("T"," ").replace(":00Z","")
    }
    this.busi.bookClassRooom(params).subscribe(
      data=>{
        this.native.showToast("预定成功!");
        this.navCtrl.pop();
      },
      error=>{

      }
    );
  }

}
